package com.zhaojp.demo.event;

import com.zhaojp.demo.domain.User;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * 使用@EventListener方法实现注册事件 ‘同步’ 监听
 */
@Component
public class EventListeners {
    /**
     * 注册监听实现方法
     * @param userRegisterEvent 用户注册事件
     */
    @EventListener
    public void register(UserRegisterEvent userRegisterEvent) throws InterruptedException {
        User user = userRegisterEvent.getUser();
        //输出注册用户信息
        System.out.println("@EventListener获取到注册信息，用户名：" + user.getName() + ",开始生产数据！");
    }

    @EventListener
    public void sendMail(UserRegisterEvent userRegisterEvent) {
        User user = userRegisterEvent.getUser();
        System.out.println("为用户"+user.getName()+"生产初始密码："+UUID.randomUUID()+",准备发送邮件.....");
    }
}
